package net.sourceforge.jweb.jstl.fn;

import java.util.Collection;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

public class MapUtil {
	public static int size(Map<?, ?> map) {
		return map == null ? 0 : map.size();
	}

	public static Object get(Map<?, ?> map, Object key) {
		if (map == null)
			return null;
		return map.get(key);
	}

	public static boolean isEmpty(Map<?, ?> map) {
		return map == null ? true : map.isEmpty();
	}

	public static boolean containsKey(Map<?, ?> map, Object key) {
		return map == null ? false : map.containsKey(key);
	}

	public static boolean containsValue(Map<?, ?> map, Object value) {
		return map == null ? false : map.containsValue(value);
	}

	public static Object put(Map<Object, Object> map, Object key, Object value) {
		if (map == null)
			return null;
		return map.put(key, value);
	}

	public static Object remove(Map<Object, Object> map, Object key) {
		if (map == null)
			return null;
		return map.remove(key);
	}

	public static void putAll(Map<Object, Object> map, Map<Object, Object> map2) {
		if (map != null)
			map.putAll(map2);
	}

	public static void clear(Map<Object, Object> map) {
		if (map != null)
			map.clear();
	}

	public static Set<Object> keySet(Map<Object, Object> map) {
		return map == null ? new HashSet<Object>() : map.keySet();
	}

	public static Collection<Object> values(Map<Object, Object> map) {
		return map == null ? new HashSet<Object>() : map.values();
	}

	public static Set<Entry<Object, Object>> entrySet(Map<Object, Object> map) {
		return map == null ? new HashSet<Entry<Object, Object>>() : map.entrySet();
	}
}
